using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class coin : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.tag == "Card" || collision.tag == "Player")
        {
            gameObject.GetComponent<CircleCollider2D>().enabled = false;
            StartCoroutine(DeleteObject(gameObject));
        }
    }
    IEnumerator DeleteObject(GameObject gameObject)
    {
        SpriteRenderer sp = gameObject.GetComponent<SpriteRenderer>();
        float time = 0f;
        while (time < 1f)
        {
            time += Time.deltaTime;
            sp.color = new Color(sp.color.r, sp.color.g, sp.color.b, sp.color.a * (1 - time));
            yield return null;
        }
        gameObject.SetActive(false);
    }
}
